/**
 * License Agreement.
 *
 * Rich Faces - Natural Ajax for Java Server Faces (JSF)
 *
 * Copyright (C) 2007 Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package fr.xde.f2f.model;

import java.util.List;

import javax.faces.context.FacesContext;

import org.ajax4jsf.config.FacesConfig;
import org.richfaces.component.UITree;
import org.richfaces.model.TreeRowKey;

/**
 * @author $Autor$
 *
 */
public class ArborescenceBean {
	
	public OrgaEntry getRacine(){

		OrgaGroup root = buildGroup(null,"SGCIB",20L,"SGCIB");
		OrgaGroup itec = buildGroup(root,"ITEC",23L,"ITEC");
		OrgaGroup rrf = buildGroup(itec,"ITEC/RRF",231L, "RRF");
		OrgaGroup cre = buildGroup(rrf,"ITEC/RRF/CRE",2311L,"CRE");
		OrgaGroup rxc = buildGroup(cre,"ITEC/RRF/CRE/RXC",2311L,"RXC");
		buildPerson(rxc, "ITEC/RRF/CRE/MRP/RXC/CLE", 1L, "Corinne LESPAGNOL");
		buildPerson(rxc, "ITEC/RRF/CRE/MRP/RXC/AHA", 2L, "Abib HAMRI");
		buildPerson(rxc, "ITEC/RRF/CRE/MRP/RXC/GSU", 3L, "Guy-Alexandre SUERMONDT");
		buildPerson(rxc, "ITEC/RRF/CRE/MRP/RXC/JBI", 4L, "JeanClaude BINOCHE");
		OrgaGroup fcc = buildGroup(itec,"ITEC/FCC",25L,"FCC");
		OrgaGroup pcl = buildGroup(fcc,"ITEC/FCC/PCL",251L,"PCL");
		buildPerson(pcl, "ITEC/FCC/PCL/NBO", 5L, "Nicolas BOURGEOIS");
		buildPerson(pcl, "ITEC/FCC/PCL/ILO", 6L, "Igor LOVICH");
		OrgaGroup glfi = buildGroup(root,"GLFI",27L,"GLFI");
		OrgaGroup xyz = buildGroup(glfi,"GLFI/XYZ",278L,"XYZ");
		OrgaGroup nat = buildGroup(xyz,"GLFI/XYZ/NAT",2780L,"NAT");
		buildPerson(nat, "GLFI/XYZ/NAT/JDU",7L,"Jean DUPONT");
		buildPerson(nat, "GLFI/XYZ/NAT/EDU",8L,"Eric DURAND");
		
		return root;
	}
	

	
	protected OrgaGroup buildGroup(OrgaGroup parent, String key, Long dbId, String mnemonic){
		OrgaGroup group = new OrgaGroup();
		group.setDbId(dbId);
		group.setKey(key);
		group.setMnemonic(mnemonic);
		if (parent!=null) parent.addSubGroup(group);
		return group;
	}
	
	protected OrgaPerson buildPerson(OrgaGroup parent, String key, Long dbId, String mnemonic){
		OrgaPerson p = new OrgaPerson();
		p.setDbId(dbId);
		p.setKey(key);
		p.setMnemonic(mnemonic);
		parent.addPerson(p);
		return p;
	}
	
	public Boolean isOpen(UITree t){
		if(!t.isExpanded()){
			TreeRowKey k = (TreeRowKey) t.getRowKey();
			return k==null || k.depth() < 4;
		} else {
			return t.isExpanded();
		}
	}
	
	
}